package com.offcn.controller;

import com.offcn.entity.News;
import com.offcn.mapper.NewsMapper;
import com.offcn.service.NewsService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class NewsController {
    @Resource
    private NewsMapper newsMapper;

    @Resource
    private NewsService newsService;
    @RequestMapping(value = "/newsShow")
    public  String newsShow(Model model){
       List<News> newsList = newsMapper.selectByAll();
        model.addAttribute("newsList",newsList);
        return "index";
    }

    @RequestMapping(value = "/newsDetail")
    public String newsById(@RequestParam(value = "id",required = false)int id, Model model){
       News news= newsService.selectById(id);
       model.addAttribute("news",news);
       return "news";
    }


}
